package net.lzzy.practices.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *@author hzl on 2022/5/12.
 *Description:
 */
public class StringUtils {
    public static  String md5Encode(String origin,String salt){
        try{
            MessageDigest digest=MessageDigest.getInstance("MD5");
            if (salt!=null&&salt.length()>0){
                origin+=salt;

            }
            digest.update(origin.getBytes());
            byte[] bytes= digest.digest();
            int i;
            StringBuilder buffer=new StringBuilder();
            for (byte b:bytes){
                i=b;
                if (i<0){
                    i+=256;
                }
                if (i<16){
                    buffer.append("0");
                }
                buffer.append(Integer.toHexString(i));
            }
            return buffer.toString();

        }catch (NoSuchAlgorithmException e){
            e.printStackTrace();
            return null;
        }
    }
    public static boolean isEmpty(String str){
        return str==null||str.isEmpty();
    }

}

